from django.db import models
from django.utils import timezone


class HostStatistics(models.Model):
    """主机数量统计模型"""
    STAT_TYPE_CHOICES = [
        ('daily', '日报'),
        ('weekly', '周报'),
        ('monthly', '月报'),
    ]
    
    stat_date = models.DateField(verbose_name='统计日期')
    stat_type = models.CharField(max_length=20, choices=STAT_TYPE_CHOICES, default='daily', verbose_name='统计类型')
    city_name = models.CharField(max_length=100, verbose_name='城市名称')
    data_center_name = models.CharField(max_length=100, verbose_name='机房名称')
    total_hosts = models.IntegerField(default=0, verbose_name='主机总数')
    online_hosts = models.IntegerField(default=0, verbose_name='在线主机数')
    offline_hosts = models.IntegerField(default=0, verbose_name='离线主机数')
    maintenance_hosts = models.IntegerField(default=0, verbose_name='维护中主机数')
    created_at = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    
    class Meta:
        verbose_name = '主机统计'
        verbose_name_plural = '主机统计'
        ordering = ['-stat_date', 'city_name', 'data_center_name']
        unique_together = ['stat_date', 'city_name', 'data_center_name']
    
    def __str__(self):
        return f"{self.stat_date} - {self.city_name}-{self.data_center_name} - 总数:{self.total_hosts}"
